<?php

namespace App\Services;
use Mail, Auth, Log;

class EmailService
{
    public static function SystemExceptionNotification($title,$info)
    {
        $elists = [["name" => '天天客服', 'email' => "714628712@qq.com"],["name" => '天天客服', 'email' => "714628712@qq.com"]];

        foreach ($elists as $elist) {
            $data = ["sendto" => $elist["email"], "name" => $elist["name"], "title" => $title, "info" => $info];

            Mail::send('admin.emails.exception', $data, function ($message) use ($data) {
                $message->from(env("MAIL_USERNAME"), "每日推广助手");
                $message->to($data['sendto'], $data['name'])->subject($data['title']);
            });
        }
    }

    // 小程序被封管理员提醒
    public static function miniappDisableNotice($emailLists,$miniappName,$message,$appid)
    {
        foreach ($emailLists as $emailList) {
            $emailData = ["sendto"=>$emailList,"miniappName"=>$miniappName,"title"=>"天天外链-小程序异常提醒","notice"=>$message,"appid"=>$appid];
            Mail::send('admin.emails.miniapp_disable', $emailData, function ($message) use ($emailData) {
                $message->from(env("MAIL_USERNAME"), "天天外链");
                $message->to($emailData['sendto'], "外链用户")->subject($emailData['title']);
            });
        }
    }

    // 系统自动切换小程序提醒
    public static function miniappChangedNotice($emailInfo)
    {
        // 管理员邮箱列表
        $adminEmailLists = [["name" => '天天客服', 'email' => "714628712@qq.com"],["name" => '天天客服', 'email' => "609787268@qq.com"],["name" => '天天客服', 'email' => "1406816402@qq.com"]];
        $typeLists = ["","通用小程序","公众号专用","二维码专用","客服专用","点击版专用","免费用户使用"];
        $statusLists = ["","独家小程序","公用小程序"];

        foreach ($adminEmailLists as $adminEmailList) {
            $emailData = ["sendto" => $adminEmailList["email"], "name" => $adminEmailList["name"], "title" => "被封小程序自动切换提醒", "emailInfo" => $emailInfo,"status" => $statusLists[$emailInfo["status"]],"type" => $typeLists[$emailInfo["type"]]];

            Mail::send('admin.emails.miniapp_changed', $emailData, function ($message) use ($emailData) {
                $message->from(env("MAIL_USERNAME"), "天天外链");
                $message->to($emailData['sendto'], $emailData['name'])->subject($emailData['title']);
            });
        }
    }

    // 通知管理员没有新的小程序了
    public static function publicMiniappEmpty($emailInfo)
    {
        // 管理员邮箱列表
        $adminEmailLists = [["name" => '天天客服', 'email' => "714628712@qq.com"],["name" => '天天客服', 'email' => "609787268@qq.com"],["name" => '天天客服', 'email' => "1406816402@qq.com"]];
        $typeLists = ["","通用小程序","公众号专用","二维码专用","客服专用","点击版专用","免费用户使用"];
        $statusLists = ["","独家小程序","公用小程序"];

        foreach ($adminEmailLists as $adminEmailList) {
            $emailData = ["sendto" => $adminEmailList["email"], "name" => $adminEmailList["name"], "title" => "请尽快上架小程序", "emailInfo" => $emailInfo,"status" => $statusLists[$emailInfo["status"]],"type" => $typeLists[$emailInfo["type"]]];

            Mail::send('admin.emails.miniapp_empty', $emailData, function ($message) use ($emailData) {
                $message->from(env("MAIL_USERNAME"), "天天外链");
                $message->to($emailData['sendto'], $emailData['name'])->subject($emailData['title']);
            });
        }
    }

    public static function sendLinkRecordEmail($email,$name,$title,$info,$links_id)
    {
        $data = ["sendto" => $email, "name" => $name, "title" => $title, "info" => $info,"links_id"=>$links_id];
        Mail::send('admin.emails.exception', $data, function ($message) use ($data) {
            $message->from(env("MAIL_USERNAME"), "天天外链");
            $message->to($data['sendto'], $data['name'])->subject($data['title']);
            $message->attach(public_path("/excel/export/".$data['links_id'].".xlsx"));
        });
    }
}
